import java.util.*;

interface IntegerStack {
    public Integer push(Integer item);

    public Integer pop();

    public Integer peek();

    public boolean empty();

    public int size();
}

class ArrayListIntegerStack implements IntegerStack {
    List<Integer> stack = new ArrayList<Integer>();

    @Override
    public Integer push(Integer item) {
        stack.add(item);
        return item;
    }

    @Override
    public Integer pop() {
        if (stack.isEmpty())
            return null;
       
        return stack.remove(stack.size() - 1);
    }

    @Override
    public Integer peek() {
        if(stack.isEmpty())
            return null;
       
        return stack.get(stack.size()- 1);

    }

    @Override
    public boolean empty() {
        return stack.isEmpty();
    }

    @Override
    public int size() {
        return stack.size();
    }

    public String toString() {
        return stack.toString();
    }

}

public class Week08_7_1 {

    public static void main(String[] args) {
        ArrayListIntegerStack stack = new ArrayListIntegerStack();
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            stack.push(sc.nextInt());
            System.out.println(stack.peek());
        }
        System.out.println(stack.peek() + "," + stack.empty() + "," + stack.size());
        System.out.println(stack.toString());
        int x = sc.nextInt();
        for (int i = 0; i < x; i++) {
            System.out.println(stack.pop());
        }
        System.out.println(stack.peek() + "," + stack.empty() + "," + stack.size());
        System.out.println(stack.toString());
        sc.close();
    }
}